package com.sise.dubbo.service.impl;

import com.sise.dubbo.dao.UserDao;
import com.sise.dubbo.dto.RpcRespDTO;
import com.sise.dubbo.dto.user.UserDTO;
import com.sise.dubbo.model.UserPO;
import com.sise.dubbo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zitian
 * @data 2019/1/12
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public RpcRespDTO<Boolean> batchInsertUser(List<UserDTO> userDTOList) {
        if(CollectionUtils.isEmpty(userDTOList)){
            log.error("[用户服务]用户批量插入为空，参数错误！");
            return new RpcRespDTO().buildErrorParamResp(false);
        }
        List<UserPO> userPOS=new ArrayList<UserPO>();
        for (UserDTO userDTO : userDTOList) {
            UserPO userPO=new UserPO();
            BeanUtils.copyProperties(userDTO,userPO);
            userPOS.add(userPO);
        }
        userDao.batchInsertUserPO(userPOS);
        return new RpcRespDTO().buildFailResp(true);
    }


}
